package com.ruoyi.info.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.info.domain.FhInfoUser;
import com.ruoyi.info.service.IFhInfoUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/info/user")
public class FhInfoUserController extends BaseController
{
    @Autowired
    private IFhInfoUserService fhInfoUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(FhInfoUser fhInfoUser)
    {
        startPage();
        List<FhInfoUser> list = fhInfoUserService.selectFhInfoUserList(fhInfoUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:user:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FhInfoUser fhInfoUser)
    {
        List<FhInfoUser> list = fhInfoUserService.selectFhInfoUserList(fhInfoUser);
        ExcelUtil<FhInfoUser> util = new ExcelUtil<FhInfoUser>(FhInfoUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fhInfoUserService.selectFhInfoUserById(id));
    }

    /**
     * 根据用户id获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:user:query')")
    @GetMapping(value = "/userId/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(fhInfoUserService.selectFhInfoUserByUserId(userId));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('info:user:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FhInfoUser fhInfoUser)
    {
        return toAjax(fhInfoUserService.insertFhInfoUser(fhInfoUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('info:user:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FhInfoUser fhInfoUser)
    {
        return toAjax(fhInfoUserService.updateFhInfoUser(fhInfoUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('info:user:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fhInfoUserService.deleteFhInfoUserByIds(ids));
    }
}
